package com.my.study.queue;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.PriorityBlockingQueue;

/**
 * @author: yidujun
 * @create: 2021/06/16 20:20
 */
@Slf4j(topic = "c.TestPriorityBlockingQueue")
public class TestPriorityBlockingQueue {

    public static void main(String[] args) {
        PriorityBlockingQueue<User> users = new PriorityBlockingQueue<>();
        users.add(new User(3, "C"));
        users.add(new User(1, "A"));
        users.add(new User(4, "F"));
        users.add(new User(6, "G"));
        users.add(new User(2, "B"));

        users.forEach(System.out::println);

        System.out.println("-----------------------");

        while (users.size() > 0){
            System.out.println(users.poll());
            users.forEach(System.out::println);
            System.out.println("-----------------------");
        }
        System.out.println(users.size());

    }
}

class User implements Comparable<User> {
    private int no;
    private String name;

    public User() {
    }

    public User(int no, String name) {
        this.no = no;
        this.name = name;
    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public int compareTo(User o) {
        return this.getNo() - o.getNo();
    }

    @Override
    public String toString() {
        return "User{" + "no=" + no + ", name=" + name + "}";
    }
}
